package com.alibaba.citrus.ots.common.util;

import lombok.Data;

/**
 * @author zhoubc
 * @description: TODO
 * @date 2021/12/27 10:28
 */
@Data
public class ThreadPageUtil {

    private static final int DEFAULT_SIZE = 500;

    private int pageSize = DEFAULT_SIZE;

    private int start;

    // 总数据量
    private int totalSize;
    // 总页数
    private int totalPage;
    // 当前页
    private int currPage;
    // 上一页
    private int prevPage;
    // 下一页
    private int nextPage;

    public ThreadPageUtil(int totalSize){
        this.totalSize = totalSize;
        this.currPage = 1;
    }

    public ThreadPageUtil(int totalSize, int pageSize){
        this.totalSize = totalSize;
        this.pageSize = pageSize;
        this.currPage = 1;
    }

    private Integer getTotalPage(){
        return (totalSize + pageSize - 1)/pageSize;
    }

    private Integer getPrevPage(){
        return currPage - 1;
    }

    private Integer getNextPage(){
        return currPage + 1;
    }

    private void turnPage(){
        start += pageSize;
        currPage = currPage +1;
    }

    public static Integer calculateTotalPage(int totalSize,int pageSize){
        return (totalSize + pageSize - 1)/pageSize;
    }

}
